package com.ruoyi.system.controller;

import java.io.InputStream;
import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;


import com.ruoyi.system.aliyun.AliyunOSSUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.FinanceWithdrawals;
import com.ruoyi.system.service.IFinanceWithdrawalsService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 提现订单管理Controller
 * 
 * @author ruoyi
 * @date 2024-10-31
 */
@RestController
@RequestMapping("/withdrawals")
public class FinanceWithdrawalsController extends BaseController
{
    @Autowired
    private IFinanceWithdrawalsService financeWithdrawalsService;

    @Autowired
    private AliyunOSSUtils aliyunOSSUtils;
    /**
     * 查询提现订单管理列表
     */
    @RequiresPermissions("finance_withdrawals:withdrawals:list")
    @GetMapping("/list")
    public TableDataInfo list(FinanceWithdrawals financeWithdrawals)
    {
        startPage();
        List<FinanceWithdrawals> list = financeWithdrawalsService.selectFinanceWithdrawalsList(financeWithdrawals);
        return getDataTable(list);
    }

    /**
     * 导出提现订单管理列表
     */
    @RequiresPermissions("finance_withdrawals:withdrawals:export")
    @Log(title = "提现订单管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FinanceWithdrawals financeWithdrawals)
    {
        List<FinanceWithdrawals> list = financeWithdrawalsService.selectFinanceWithdrawalsList(financeWithdrawals);
        ExcelUtil<FinanceWithdrawals> util = new ExcelUtil<FinanceWithdrawals>(FinanceWithdrawals.class);
        util.exportExcel(response, list, "提现订单管理数据");
    }

    /**
     * 获取提现订单管理详细信息
     */
    @RequiresPermissions("finance_withdrawals:withdrawals:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(financeWithdrawalsService.selectFinanceWithdrawalsById(id));
    }

    /**
     * 新增提现订单管理
     */
    @RequiresPermissions("finance_withdrawals:withdrawals:add")
    @Log(title = "提现订单管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FinanceWithdrawals financeWithdrawals)
    {
        return toAjax(financeWithdrawalsService.insertFinanceWithdrawals(financeWithdrawals));
    }

    /**
     * 修改提现订单管理
     */
    @RequiresPermissions("finance_withdrawals:withdrawals:edit")
    @Log(title = "提现订单管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FinanceWithdrawals financeWithdrawals)
    {
        return toAjax(financeWithdrawalsService.updateFinanceWithdrawals(financeWithdrawals));
    }

    /**
     * 删除提现订单管理
     */
    @RequiresPermissions("finance_withdrawals:withdrawals:remove")
    @Log(title = "提现订单管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(financeWithdrawalsService.deleteFinanceWithdrawalsByIds(ids));
    }

    /**
     * 导入会员订单管理数据
     */
    @RequiresPermissions("finance_withdrawals:withdrawals:import")
    @Log(title = "提现订单管理", businessType = BusinessType.IMPORT)
   @PostMapping("/import")
    public AjaxResult importData(@RequestParam("file") MultipartFile file) throws IOException
    {
        ExcelUtil<FinanceWithdrawals> util = new ExcelUtil<FinanceWithdrawals>(FinanceWithdrawals.class);
        List<FinanceWithdrawals> financeMemberList = util.importExcel(file.getInputStream());
        financeWithdrawalsService.importFinanceMember(financeMemberList);
        return success();
    }

    //图片上传下载
    @RequestMapping("fileUpload")
    public String upload(MultipartFile file) throws IOException {
        String originalFilename = file.getOriginalFilename();
        InputStream inputStream = file.getInputStream();
        String s = aliyunOSSUtils.putObject(inputStream, originalFilename);
        return s;
    }

}
